package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bussiness.domain.SysBusinessPolicy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SysBusinessDynamicType;
import com.ruoyi.bussiness.service.ISysBusinessDynamicTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务-动态类别Controller
 *
 * @author ruoyi
 * @date 2023-12-12
 */
@RestController
@RequestMapping("/bussiness/dynamicType")
public class SysBusinessDynamicTypeController extends BaseController
{
    @Autowired
    private ISysBusinessDynamicTypeService sysBusinessDynamicTypeService;

    /**
     * 查询业务-动态类别列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessDynamicType sysBusinessDynamicType)
    {
        startPage();
        List<SysBusinessDynamicType> list = sysBusinessDynamicTypeService.selectSysBusinessDynamicTypeList(sysBusinessDynamicType);
        return getDataTable(list);
    }

    /**
     * 导出业务-动态类别列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:export')")
    @Log(title = "业务-动态类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessDynamicType sysBusinessDynamicType)
    {
        List<SysBusinessDynamicType> list = sysBusinessDynamicTypeService.selectSysBusinessDynamicTypeList(sysBusinessDynamicType);
        ExcelUtil<SysBusinessDynamicType> util = new ExcelUtil<SysBusinessDynamicType>(SysBusinessDynamicType.class);
        util.exportExcel(response, list, "业务-动态类别数据");
    }

    /**
     * 获取业务-动态类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:query')")
    @GetMapping(value = "/{dynamicTypeId}")
    public AjaxResult getInfo(@PathVariable("dynamicTypeId") Long dynamicTypeId)
    {
        return success(sysBusinessDynamicTypeService.selectSysBusinessDynamicTypeByDynamicTypeId(dynamicTypeId));
    }

    /**
     * 新增业务-动态类别
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:add')")
    @Log(title = "业务-动态类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessDynamicType sysBusinessDynamicType)
    {
        return toAjax(sysBusinessDynamicTypeService.insertSysBusinessDynamicType(sysBusinessDynamicType));
    }

    /**
     * 修改业务-动态类别
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:edit')")
    @Log(title = "业务-动态类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessDynamicType sysBusinessDynamicType)
    {
        return toAjax(sysBusinessDynamicTypeService.updateSysBusinessDynamicType(sysBusinessDynamicType));
    }

    /**
     * 删除业务-动态类别
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:remove')")
    @Log(title = "业务-动态类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dynamicTypeIds}")
    public AjaxResult remove(@PathVariable Long[] dynamicTypeIds)
    {
        return toAjax(sysBusinessDynamicTypeService.deleteSysBusinessDynamicTypeByDynamicTypeIds(dynamicTypeIds));
    }

    /**
     * 上移下移政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:edit')")
    @Log(title = "业务-动态类别", businessType = BusinessType.UPDATE)
    @PutMapping("/moveUpOrDown")
    public AjaxResult moveUpOrDown(@RequestBody SysBusinessDynamicType entity)
    {
        return sysBusinessDynamicTypeService.moveUpOrDown(entity);
    }

    /**
     * 置顶 置底政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:dynamicType:edit')")
    @Log(title = "业务-动态类别", businessType = BusinessType.UPDATE)
    @PutMapping("/pinToTopOrEnd")
    public AjaxResult pinToTopOrEnd(@RequestBody SysBusinessDynamicType entity)
    {
        return sysBusinessDynamicTypeService.pinToTopOrEnd(entity);
    }
}
